package org.jit.banking;

import java.util.Scanner;

import static java.lang.System.out;

/**
 * @author 水杉metasequoia
 */
public class TestBank {
    public static void main(String[] args) {
        out.println("----------银行系统----------");
        out.println("请选择操作：1.开储蓄账户 2.开信用账户 3.退出");
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        switch(i)
        {
            case 1: {
                out.print("请输入开户金额：");
                double balance = sc.nextDouble();
                out.print("请输入储蓄利率(以小数形式)：");
                double rate = sc.nextDouble();
                SavingsAccount sa = new SavingsAccount(balance,rate);
                out.println("一个储蓄周期后的账户余额为："+sa.getBalance());

                int flag = 1;
                while(flag==1){
                    out.println("");
                    out.println("请选择操作：1.继续等待一个储蓄周期 2.存款 3.取款 4.退出");
                    int o = sc.nextInt();
                    switch (o)
                    {
                        case 1:
                            sa = new SavingsAccount(sa.getBalance(),sa.getInterestRate());
                            out.println("又一个储蓄周期后账户余额为："+String.format("%.2f",sa.getBalance()));
                            break;
                        case 2:
                            out.print("请输入存款金额：");
                            double add = sc.nextDouble();
                            sa.deposit(add);
                            out.println("账户余额为："+String.format("%.2f",sa.getBalance()));
                            break;
                        case 3:
                            out.print("请输入取款金额：");
                            double draw = sc.nextDouble();
                            sa.withdraw(draw);
                            out.println("账户余额为："+String.format("%.2f",sa.getBalance()));
                            break;
                        case 4:
                            flag = 0;
                            break;
                        default:
                            out.println("捣乱是吧");
                            System.exit(0);
                    }
                }
                break;
            }
            case 2: {
                out.print("请输入开户金额：");
                double balance = sc.nextDouble();
                out.print("请输入透支额度：");
                double over = sc.nextDouble();
                CheckingAccount ca = new CheckingAccount(balance,over);
                int flag = 1;
                while(flag==1){
                    out.println("");
                    out.println("请选择操作：1.修改透支额度 2.存款 3.取款 4.查看账户信息 5.退出");
                    int o = sc.nextInt();
                    switch (o)
                    {
                        case 1:
                            out.print("请输入新的透支额度：");
                            over = sc.nextDouble();
                            ca.setPrivateOverdraftProtection(over);
                            out.println("当前账户余额："+ca.getBalance()+" 原始透支额度："+over);
                            break;
                        case 2:
                            out.print("请输入存款金额：");
                            double add = sc.nextDouble();
                            ca.deposit(add);
                            break;
                        case 3:
                            out.print("请输入取款金额：");
                            double draw = sc.nextDouble();
                            if(!ca.withdraw(draw)){
                                out.println("即使透支也不足以取出这巨款哩。");
                            }
                            break;
                        case 4:
                            out.println("账户余额为："+ca.getBalance());
                            out.println("原始透支额度为："+ca.getPrivateOverdraftProtection());
                            out.println("剩余透支额度为："+ca.getOverdraftProtection());
                            break;
                        case 5:
                            flag = 0;
                            break;
                        default:
                            out.println("捣乱是吧");
                            System.exit(0);
                    }
                }
            }
            case 3:
                System.exit(0);
            default:
                out.println("捣乱是吧");
                System.exit(0);
        }
    }
}
